#include <stdio.h>


static inline unsigned char SpiReverseBitOrder(unsigned short Data)
{
    unsigned char DataOut = ((Data & 0x01) << 7) |
                    ((Data & 0x02) << 5) |
                    ((Data & 0x04) << 3) |
                    ((Data & 0x08) << 1) |
                    ((Data & 0x10) >> 1) |
                    ((Data & 0x20) >> 3) |
                    ((Data & 0x40) >> 5) |
                    ((Data & 0x80) >> 7);

    return DataOut;
}

int main(int argc, char ** argv)
{
	int ret;

	ret = SpiReverseBitOrder(0x34);
	printf("%d:0x%x\n", __LINE__, ret);
}

#if 0
/*
 * intel
 */


/*
 * arm v8
 */
static inline unsigned char SpiReverseBitOrder(unsigned short Data)
{
  400590:	d10083ff 	sub	sp, sp, #0x20 ; sp = sp - 0x20
  400594:	79001fe0 	strh	w0, [sp, #14] ; data
    unsigned char DataOut = ((Data & 0x01) << 7) |
  400598:	79401fe0 	ldrh	w0, [sp, #14] ; data
  40059c:	53196000 	lsl	w0, w0, #7        ; w0 = data << 7
  4005a0:	13001c01 	sxtb	w1, w0        ; w1 = data << 7
                    ((Data & 0x02) << 5) |
  4005a4:	79401fe0 	ldrh	w0, [sp, #14] ; data
  4005a8:	531b6800 	lsl	w0, w0, #5        ; w0 = data << 5
  4005ac:	13001c00 	sxtb	w0, w0        ; w0 extend 
  4005b0:	121a0000 	and	w0, w0, #0x40     ; w0 = data << 5 + 0x40
  4005b4:	13001c00 	sxtb	w0, w0        ; w0 extend
    unsigned char DataOut = ((Data & 0x01) << 7) |
  4005b8:	2a000020 	orr	w0, w1, w0 ; w0 = data << 7 | data << 5 + 0x40
  4005bc:	13001c01 	sxtb	w1, w0 ; w1 = extend w0
                    ((Data & 0x04) << 3) |
  4005c0:	79401fe0 	ldrh	w0, [sp, #14] ; data
  4005c4:	531d7000 	lsl	w0, w0, #3        ; w0 = data << 3
  4005c8:	13001c00 	sxtb	w0, w0        ; w0 extend w0
  4005cc:	121b0000 	and	w0, w0, #0x20     ; w0 = data << 3 & 0x20
  4005d0:	13001c00 	sxtb	w0, w0        ; w0 extend
                    ((Data & 0x02) << 5) |
  4005d4:	2a000020 	orr	w0, w1, w0 ; w0 = w1 | w0
  4005d8:	13001c01 	sxtb	w1, w0 ; w1 extend w0
                    ((Data & 0x08) << 1) |
  4005dc:	79401fe0 	ldrh	w0, [sp, #14]
  4005e0:	531f7800 	lsl	w0, w0, #1
  4005e4:	13001c00 	sxtb	w0, w0
  4005e8:	121c0000 	and	w0, w0, #0x10
  4005ec:	13001c00 	sxtb	w0, w0
                    ((Data & 0x04) << 3) |
  4005f0:	2a000020 	orr	w0, w1, w0
  4005f4:	13001c01 	sxtb	w1, w0
                    ((Data & 0x10) >> 1) |
  4005f8:	79401fe0 	ldrh	w0, [sp, #14]
  4005fc:	13017c00 	asr	w0, w0, #1
  400600:	13001c00 	sxtb	w0, w0
  400604:	121d0000 	and	w0, w0, #0x8
  400608:	13001c00 	sxtb	w0, w0
                    ((Data & 0x08) << 1) |
  40060c:	2a000020 	orr	w0, w1, w0
  400610:	13001c01 	sxtb	w1, w0
                    ((Data & 0x20) >> 3) |
  400614:	79401fe0 	ldrh	w0, [sp, #14] ; data
  400618:	13037c00 	asr	w0, w0, #3 ; w0 = w0 >> 3
  40061c:	13001c00 	sxtb	w0, w0
  400620:	121e0000 	and	w0, w0, #0x4
  400624:	13001c00 	sxtb	w0, w0
                    ((Data & 0x10) >> 1) |
  400628:	2a000020 	orr	w0, w1, w0
  40062c:	13001c01 	sxtb	w1, w0
                    ((Data & 0x40) >> 5) |
  400630:	79401fe0 	ldrh	w0, [sp, #14]
  400634:	13057c00 	asr	w0, w0, #5
  400638:	13001c00 	sxtb	w0, w0
  40063c:	121f0000 	and	w0, w0, #0x2
  400640:	13001c00 	sxtb	w0, w0
                    ((Data & 0x20) >> 3) |
  400644:	2a000020 	orr	w0, w1, w0
  400648:	13001c01 	sxtb	w1, w0
                    ((Data & 0x80) >> 7);
  40064c:	79401fe0 	ldrh	w0, [sp, #14]
  400650:	13077c00 	asr	w0, w0, #7
  400654:	13001c00 	sxtb	w0, w0
  400658:	12000000 	and	w0, w0, #0x1
  40065c:	13001c00 	sxtb	w0, w0
                    ((Data & 0x40) >> 5) |
  400660:	2a000020 	orr	w0, w1, w0
  400664:	13001c00 	sxtb	w0, w0
    unsigned char DataOut = ((Data & 0x01) << 7) |
  400668:	39007fe0 	strb	w0, [sp, #31] ; dataOute

    return DataOut;
  40066c:	39407fe0 	ldrb	w0, [sp, #31]
}
  400670:	910083ff 	add	sp, sp, #0x20
  400674:	d65f03c0 	ret

0000000000400678 <main>:

void main(int argc, char ** argv)
{
  400678:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  40067c:	910003fd 	mov	x29, sp
  400680:	b9001fa0 	str	w0, [x29, #28]
  400684:	f9000ba1 	str	x1, [x29, #16]
	int ret;

	ret = SpiReverseBitOrder(0x34);
  400688:	52800680 	mov	w0, #0x34                  	// #52
  40068c:	97ffffc1 	bl	400590 <SpiReverseBitOrder>
  400690:	53001c00 	uxtb	w0, w0
  400694:	b9002fa0 	str	w0, [x29, #44] ; ret
	printf("%d:0x%x\n", __LINE__, ret);
  400698:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  40069c:	911d4000 	add	x0, x0, #0x750 ; parameter
  4006a0:	b9402fa2 	ldr	w2, [x29, #44] ; ret
  4006a4:	528002e1 	mov	w1, #0x17                  	// #23
  4006a8:	97ffff62 	bl	400430 <printf@plt>
}

/*
 * arm v7
 */


#endif